package org.yzh.client.netty;

import io.github.yezhihao.netmc.codec.MessageDecoder;
import io.github.yezhihao.netmc.codec.MessageEncoder;

public class ClientConfig {

    protected final String ip;
    protected final int port;
    protected final int maxFrameLength;
    protected final byte[] delimiter;
    protected final MessageDecoder decoder;
    protected final MessageEncoder encoder;
    protected final HandlerMapping handlerMapping;
    protected final String deviceId;
    protected final String plateNo;
    protected final String mobileNo;

    private ClientConfig(String ip, int port, int maxFrameLength, byte[] delimiter, MessageDecoder decoder,
        MessageEncoder encoder, HandlerMapping handlerMapping, String deviceId, String plateNo, String mobileNo) {
        this.ip = ip;
        this.port = port;
        this.maxFrameLength = maxFrameLength;
        this.delimiter = delimiter;
        this.decoder = decoder;
        this.encoder = encoder;
        this.handlerMapping = handlerMapping;
        this.deviceId = deviceId;
        this.plateNo = plateNo;
        this.mobileNo = mobileNo;
    }

    public static Builder custom() {
        return new Builder();
    }

    public static class Builder {

        private String ip;
        private int port;
        private int maxFrameLength;
        private byte[] delimiters;
        private MessageDecoder decoder;
        private MessageEncoder encoder;
        private HandlerMapping handlerMapping;
        private String deviceId;
        private String plateNo;
        private String mobileNo;

        public Builder() {
        }

        public Builder setIp(String ip) {
            this.ip = ip;
            return this;
        }

        public Builder setPort(int port) {
            this.port = port;
            return this;
        }

        public Builder setMaxFrameLength(int maxFrameLength) {
            this.maxFrameLength = maxFrameLength;
            return this;
        }

        public Builder setDelimiters(byte[] delimiters) {
            this.delimiters = delimiters;
            return this;
        }

        public Builder setDecoder(MessageDecoder decoder) {
            this.decoder = decoder;
            return this;
        }

        public Builder setEncoder(MessageEncoder encoder) {
            this.encoder = encoder;
            return this;
        }

        public Builder setHandlerMapping(HandlerMapping handlerMapping) {
            this.handlerMapping = handlerMapping;
            return this;
        }

        public Builder setDeviceId(String deviceId) {
            this.deviceId = deviceId;
            return this;
        }

        public Builder setPlateNo(String plateNo) {
            this.plateNo = plateNo;
            return this;
        }

        public Builder setMobileNo(String mobileNo) {
            this.mobileNo = mobileNo;
            return this;
        }

        public ClientConfig build() {
            return new ClientConfig(
                    this.ip,
                    this.port,
                    this.maxFrameLength,
                    this.delimiters,
                    this.decoder,
                    this.encoder,
                    this.handlerMapping,
                    this.deviceId,
                    this.plateNo,
                    this.mobileNo);
        }
    }
}